import { router } from "@/cool";
import { useUi } from "@/uni_modules/cool-ui";
import { ref } from "vue";
export default function OperationHook(state: { searchForm: Base.CommonData }) {
	const { searchForm } = state;
	const goStoreDetail = (row: any) => {
		console.log("详情", row);
		uni.switchTab({
			url: "/pages/layout/home/index?id=" + row.id
		});
	};
	// 预定
	const reservationHandle = (row: any) => {
		uni.switchTab({
			url: "/pages/layout/home/index?id=" + row.id
		});
	};
	// 选择城市
	const selectCityHandle = () => {
		router.to("/pages/businessPages/home/selectCity/index");
	};
	// 导航到店
	const goStoreLocationHandle = () => {
		uni.getLocation({
			type: "gcj02",
			success: (res) => {
				console.log("导航到店", res);
				uni.openLocation({
					latitude: res.latitude,
					longitude: res.longitude,
					name: "店铺地址",
					address: "店铺地址"
				});
			}
		});
	};
	const callPhone = (phone: string) => {
		uni.makePhoneCall({
			phoneNumber: phone
		});
	};
	// 悬浮菜单交互
	const floatMenuVisible = ref<boolean>(false);
	const showFloatMenuHandle = () => {
		floatMenuVisible.value = !floatMenuVisible.value;
	};
	const ui = useUi();
	// 开大门
	const openDoorHandle = () => {
		ui.showToast({
			message: "您暂无订单，无法开大门!",
			type: "warn"
		});
	};
	// 开包厢
	const openRoomHandle = () => {
		ui.showToast({
			message: "您暂无订单，无法开包厢!",
			type: "warn"
		});
	};
	// 续单
	const continueOrderHandle = () => {
		ui.showToast({
			message: "您暂无订单，无法续单!",
			type: "warn"
		});
	};
	// 分享
	const shareHandle = () => {
		uni.share({
			provider: "weixin",
			scene: "WXSceneSession",
			title: "分享标题",
			imageUrl: "分享图片",
			success: (res) => {
				console.log("分享成功", res);
			},
			fail: (err) => {
				console.log("分享失败", err);
			}
		});
	};
	return {
		goStoreDetail,
		reservationHandle,
		goStoreLocationHandle,
		callPhone,
		selectCityHandle,
		floatMenuVisible,
		showFloatMenuHandle,
		openDoorHandle,
		openRoomHandle,
		continueOrderHandle,
		shareHandle
	};
}
